/**
 * @file main.c
 * @author LiuDongPeng
 * @brief 
 * @version 0.1
 * @date 2022-03-31
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "heap.h"


#define SIZE    20

int main(int argc, char* argv[])
{
    heap_t* heap;
    int arr[] = { 5, 7, 9, 11, 2, 4, 3 };
    int size = sizeof(arr) / sizeof(int);


    srandom((unsigned int)time(NULL));


    if ( (heap = create_heap(20)) == NULL) {
        exit(1);
    }


    for (int i = 0; i < SIZE; i++) {
        add(heap, random() % 10000);
    }

    /*
    for (int i = 0; i < size; i++) {
        heap->arr[i] = arr[i];
        heap->size++;
    }
    
    // 自顶向下的上滤
    for (int i = 1; i < size; i++) {
        sift_up(heap, i);
    }
    
    // 自下向上的下滤
    for (int i = (size / 2) - 1; i >= 0; i--) {
        sift_down(heap, i);
    }
    */


    
    for (int i = 0; i < SIZE; i++) {
        printf("top = %d\n", get_top(heap));
        remove_top(heap);
    }
    


    for (int i = 0; i < heap->size; i++) {
        printf("%d ", heap->arr[i]);
    }
    printf("\n");


    // 销毁二叉堆
    destroy_heap(heap);

    exit(0);
}